/*
 * DrawList.cpp
 *
 *  Created on: 2012/07/07
 *      Author: weihe
 */

#include "DrawList.h"
#include <iostream>

namespace object {

typedef list<Drawable*>::iterator iter;

DrawList::~DrawList()
{
	if (autoRelease) {
		for (iter it = drawableList.begin(); it != drawableList.end(); it++) {
			delete *it;
			*it = NULL;
		}
	}
}

DrawList& DrawList::operator<<(Drawable *obj)
{
	drawableList.push_back(obj);
	return *this;
}

bool DrawList::update(float dt)
{
	for (iter it = drawableList.begin(); it != drawableList.end(); it++) {
		bool live = (*it)->update(dt);
		if (!live) {
			it = drawableList.erase(it);
		}
	}
	return true;
}

void DrawList::draw()
{
	for (iter it = drawableList.begin(); it != drawableList.end(); it++) {
		(*it)->draw();
	}
}

} /* namespace object */
